package com.ghck.server.bkcontroller;

import java.security.Principal;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.ghck.server.model.Maker;
import com.ghck.server.service.MakerService;
import com.ghck.shop.model.Page;

@Controller
@RequestMapping(value="/system/maker")
public class AdminMakerController {
	
	@Autowired
	private MakerService makerService;

	@RequestMapping(value="/list")
	public String main(Maker maker,
			@RequestParam(defaultValue = "1") Integer currentPage,
			@RequestParam(defaultValue = "10") Integer pageSize,
            HttpServletRequest request){
		int start = 0;
		if(currentPage > 0 ){
			start = ((currentPage-1)*pageSize);
		}
		Page<Maker> page = new Page<Maker>(currentPage);
		page.setPageSize(pageSize);
		List<Maker> list = makerService.listMakers(maker, start, pageSize);
		page.setResultRows(list);
		page.setTotalRow(makerService.countListMakers(maker));
		request.setAttribute("page", page);
		return "back/maker/list";
	}
	
	@RequestMapping(value="/makerPass/{id}",method = RequestMethod.GET)
	public String makerPass(@PathVariable("id")Integer id){
		Maker maker = new Maker();
		maker.setId(id);
		makerService.makerPass(maker);
		return "redirect:/system/maker/list";
	}
	
	@RequestMapping(value="/makerReject/{id}",method = RequestMethod.GET)
	public String makerReject(Principal principal,@PathVariable("id")Integer id){
		Maker maker = new Maker();
		maker.setId(id);
		makerService.makerReject(maker);
		return "redirect:/system/index/list";
	}
	
}
